package edu.scau.util;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import com.jfinal.plugin.activerecord.ICallback;

public class CostUtil implements ICallback{
	
	private int pid;
	private Object result;

	public int getPid() {
		return pid;
	}

	public void setPid(int pid) {
		this.pid = pid;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}

	@Override
	public Object call(Connection conn) throws SQLException {
		 CallableStatement proc = null;      
		 try {
			 proc = conn.prepareCall("{call money(?, ?)}");
	         proc.setInt(1, pid);
	         proc.registerOutParameter(2,Types.FLOAT);
	         proc.execute();
	         setResult(proc.getObject(2));
		} finally {
			conn.close();
		}
         
        return getResult();
	}

}
